<!-- Core JS -->


<script src="/static/HubUI/js/sweetalert2.js"></script>


<!-- build:js assets/vendor/js/core.js -->
<script src="/static/HubUI/js/axios.min.js"></script>
<script>
  // 设置axios的默认请求
  axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

  // 读取本地的userInfo

</script>
<script src="/static/HubUI/assets/vendor/libs/jquery/jquery.js"></script>
<script src="/static/HubUI/assets/vendor/libs/popper/popper.js"></script>
<script src="/static/HubUI/assets/vendor/js/bootstrap.js"></script>
<script src="/static/HubUI/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
<script src="/static/HubUI/assets/vendor/js/menu.js"></script>

<!-- endbuild -->

<!-- Vendors JS -->
<script src="/static/HubUI/assets/vendor/libs/apex-charts/apexcharts.js"></script>

<!-- Main JS -->
<script src="/static/HubUI/assets/js/main.js"></script>

<!-- Page JS -->
<script src="/static/HubUI/assets/js/dashboards-analytics.js"></script>
<script src="/static/HubUI/js/Hub.js"></script>
<script>
  // 自定义JS

  // 添加请求拦截器
  axios.interceptors.request.use(async function (config) {
    // 读取本地的user
    let user = localStorage.getItem('user');
    if (user) {
      user = JSON.parse(user);
      config.headers['X-User-Id'] = user.user_id;
    }
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

  // 添加响应拦截器
  axios.interceptors.response.use(function (response) {
    // 2xx 范围内的状态码都会触发该函数。
    // 对响应数据做点什么
    console.log("成功", response);
    if(response.data.code == 401) {
      if(response.data.msg == "请先登录") {
        window.location.href = "/web/pc/login/";
      }
    }
    
    return response;
  }, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
  });
</script>